Imports Microsoft.VisualBasic

Public Class PsychCalConfigSection
    Inherits ConfigurationSection
    <ConfigurationProperty("defaultConnectionStringName", Defaultvalue:="LocalSqlServer")> Public Property DefaultConnectionStringname() As String
        Get
            Return Me("defaultConnectionStringName").ToString
        End Get
        Set(ByVal value As String)
            Me("defaultConnectionStringname") = value
        End Set
    End Property
    <ConfigurationProperty("defaultCacheDuration", DefaultValue:="600")> _
        Public Property DefaultCacheDuration() As Integer
        Get
            Return CInt(Me("defaultCacheDuration"))
        End Get
        Set(ByVal value As Integer)
            Me("defaultCacheDuration") = value
        End Set
    End Property
    <ConfigurationProperty("articles", IsRequired:=True)> _
      Public ReadOnly Property Articles() As ArticlesElement
        Get
            Return CType(Me("articles"), ArticlesElement)
        End Get
    End Property
    Public Class ArticlesElement
        Inherits ConfigurationElement

        <ConfigurationProperty("connectionStringName")> _
        Public Property ConnectionStringName() As String
            Get
                Return CStr(Me("connectionStringName"))
            End Get
            Set(ByVal value As String)
                Me("ConnectionStringName") = value
            End Set
        End Property

        Public ReadOnly Property ConnectionString() As String
            Get
                Dim connStringName As String
                If String.IsNullOrEmpty(Me.ConnectionStringName) Then
                    connStringName = Globals.Settings.DefaultConnectionStringName
                Else
                    connStringName = Me.ConnectionStringName
                End If
                Return Web.Configuration.WebConfigurationManager.ConnectionStrings(connStringName).ConnectionString
            End Get
        End Property

        <ConfigurationProperty("providerType", DefaultValue:="MB.PsychCal.DAL.SqlClient.SqlArticlesProvider")> _
        Public Property ProviderType() As String
            Get
                Return CStr(Me("providerType"))
            End Get
            Set(ByVal value As String)
                Me("providerType") = value
            End Set
        End Property
        <ConfigurationProperty("pageSize", DefaultValue:="10")> _
            Public Property PageSize() As Integer
            Get
                Return CInt(Me("pageSize"))
            End Get
            Set(ByVal value As Integer)
                Me("pageSize") = value
            End Set
        End Property

        <ConfigurationProperty("rssItems", DefaultValue:="5")> _
        Public Property RssItems() As Integer
            Get
                Return CInt(Me("rssItems"))
            End Get
            Set(ByVal value As Integer)
                Me("rssItems") = value
            End Set
        End Property

        <ConfigurationProperty("enableCaching", DefaultValue:="true")> _
        Public Property EnableCaching() As Boolean
            Get
                Return CBool(Me("enableCaching"))
            End Get
            Set(ByVal value As Boolean)
                Me("enableCaching") = value
            End Set
        End Property

        <ConfigurationProperty("cacheDuration")> _
        Public Property CacheDuration() As Integer
            Get
                Dim duration As Integer = CInt(Me("cacheDuration"))
                If duration > 0 Then
                    Return duration
                Else
                    Return Globals.Settings.DefaultCacheDuration
                End If
            End Get
            Set(ByVal value As Integer)
                Me("cacheDuration") = value
            End Set
        End Property
    End Class


End Class
